//
//  AttentionCell.m
//  FKGW
//
//  Created by song ce on 2017/2/21.
//  Copyright © 2017年 song ce. All rights reserved.
//

#import "AttentionCell.h"
#import "OSSHelper.h"
@implementation AttentionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.selectionStyle= UITableViewCellSelectionStyleNone;
    
    //添加左滑手势
    UISwipeGestureRecognizer *swipLeft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swip:)];
    swipLeft.direction=UISwipeGestureRecognizerDirectionLeft;
    [self.moveView addGestureRecognizer:swipLeft];
    //添加右滑手势
    UISwipeGestureRecognizer *swipRight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swip:)];
    swipRight.direction=UISwipeGestureRecognizerDirectionRight;
    [self.moveView addGestureRecognizer:swipRight];
    self.xOssProcess =  [NSString stringWithFormat:@"image/resize,m_fill,w_%d,h_%d",74,74];
}

-(void)setModel:(MyAttentionModel *)model{
    _model = model;
    self.goodsNameLabel.text = _model.storeName;
    self.shopIntroduceLabel.text = _model.storeIntroduce;

    [[OSSHelper sharedHelper] OSSDownLoadWithObjectKey:_model.pic  xOssProcess:self.xOssProcess downLoadBlock:^(NSData *data) {
        dispatch_async(dispatch_get_main_queue(), ^{
            self.goodImgeView.image = [UIImage imageWithData:data];
        });
    }];

   }

- (void)swip:(UISwipeGestureRecognizer *)swipe{
    
    if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
        // 打开
        [self openMenu];
        // 将其他已打开的关闭
        if( self.mySwipeBlock ){
            self.mySwipeBlock();
        }

    }else if (swipe.direction == UISwipeGestureRecognizerDirectionRight){
        // 关闭
        [self closeMenu];
    }
}

- (IBAction)cancelAttion:(UIButton *)sender {
    if(self.myDeleteBlock){
        self.myDeleteBlock();
    }
}
//侧滑
- (IBAction)swipAction:(UIButton*)sender {
    sender.selected = !sender.selected;
    if(sender.isSelected){
        [self openMenu];
    }else{
        [self closeMenu];
    }
}


- (void)openMenu{
    if (self.isOpen) {
        return;
    }
    [UIView animateWithDuration:0.5 animations:^{
        self.moveView.center = CGPointMake(self.moveView.center.x - 68, self.moveView.center.y);
    }completion:^(BOOL finished) {
        if(finished){
            self.isOpen = YES;
        }
    }];
}

/**关闭左滑菜单*/
-(void)closeMenu
{
    if(!_isOpen)
        return;
    [UIView animateWithDuration:0.5 animations:^{
        self.moveView.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, self.moveView.center.y);
    }completion:^(BOOL finished) {
        if (finished) {
            self.isOpen = NO;
        }
    }];
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
